package com.dp.springsourcecodeanalysis.web;

import org.springframework.web.bind.annotation.*;

import com.dp.springsourcecodeanalysis.web.dto.PurchaseInfoDTO;
import com.dp.springsourcecodeanalysis.web.dto.PurchaseQueryDTO;

import lombok.extern.slf4j.Slf4j;

/**
 * Created by IntelliJ IDEA
 *
 * @author shala/沙拉
 * @date 2021/12/31 15:35
 */
@RestController
@RequestMapping("/params")
@Slf4j
public class ParamsController {

    @GetMapping("/parseDto")
    public PurchaseInfoDTO parseDto(PurchaseQueryDTO dto) {
        log.info("parseDto - params: {}", dto.toString());
        return new PurchaseInfoDTO(dto.getPurchaseOrderNo(), 10001, "白色");
    }

    @GetMapping("/parse")
    public PurchaseInfoDTO parse(@RequestParam("purchaseOrderNo") String purchaseOrderNo, PurchaseQueryDTO dto) {
        log.info("parse - params: {}", purchaseOrderNo);
        log.info("parse - dto params: {}", dto.toString());
        return new PurchaseInfoDTO(dto.getPurchaseOrderNo(), 10001, "白色");
    }

    @PostMapping("/parseBody")
    public PurchaseInfoDTO parseBody(@RequestParam("purchaseOrderNo") String purchaseOrderNo,
        @RequestBody PurchaseQueryDTO dto) {
        log.info("parseBody - params: {}", purchaseOrderNo);
        log.info("parseBody - body: {}", dto.toString());
        return new PurchaseInfoDTO(dto.getPurchaseOrderNo(), 10001, "白色");
    }
}
